package myky.com.doctorapp.ui

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.DividerItemDecoration
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gyf.barlibrary.ImmersionBar
import io.reactivex.Observable
import kotlinx.android.synthetic.main.activity_help_text.*
import kotlinx.android.synthetic.main.public_common_title.*
import myky.com.doctorapp.R
import myky.com.doctorapp.adapter.HelpTextAdapter
import myky.com.doctorapp.utils.Constants
/**
 * Description: 帮助页面
 * @author xiangyao
 * Created by 2019/3/15 5:48 PM
 */
class HelpTextActivity : AppCompatActivity(), BaseQuickAdapter.OnItemChildClickListener {


    lateinit var helpTextAdapter: HelpTextAdapter
    var index: Int = 0
    val mStringArrayId = intArrayOf(R.array.login_related, R.array.message_relevant, R.array.health_records, R.array.records_relevant, R.array.consultation_relevant, R.array.remote_relevant, R.array.appointment_relevant)
    lateinit var mString: ArrayList<String>

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_help_text)

        ImmersionBar.with(this).barColorInt(resources.getColor(R.color.colorPrimary)).titleBar(R.id.commonTitleLayout).navigationBarEnable(false).init()
        initView()
    }

    private fun initView() {



        val extras = intent.extras

        index = extras.getInt(Constants.HELPTEXTINDEX)

        mString=ArrayList()

        val stringArray = resources.getStringArray(mStringArrayId[index])


        stringArray.forEach { s-> mString.add(s)}

        conmonTitleTextView.text= resources.getStringArray(R.array.problems_and_help)[index]

        helpTextAdapter= HelpTextAdapter(mString)

        activity_help_text_recycler.layoutManager = LinearLayoutManager(this)

        activity_help_text_recycler.addItemDecoration(DividerItemDecoration(this, 1))

        activity_help_text_recycler.adapter=helpTextAdapter


        backLayout.setOnClickListener { finish() }


        helpTextAdapter.onItemChildClickListener = this



    }
    override fun onItemChildClick(adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int) {


        var bundle=Bundle()

        bundle.putInt(Constants.HELPINDEX,index)
        bundle.putInt(Constants.HELPTITITLEINDEX,position)


        var intent=Intent()

        intent.setClass(this,HelpDeatailsActivity::class.java)

        intent.putExtras(bundle)

        startActivity(intent)




    }

}
